import * as api from "@/api/permission";
//递归检验路由
import recursionRoutes from "@/router/recursionRoutes";
import allRoutes from "@/router/generateRoute";
let routes = allRoutes.find((item) => item.path === "/home");
import dynamicRoute from "@/router/dynamicRoute";
import router from "@/utils/routerGurad";


export default {
  namespaced: true,
  state: {
    userMenu:[]
  },
  getters: {},
  mutations: {
    SET_USER_METU(state,payload){
      state.userMenu=[...payload]

      dynamicRoute.children=[...payload]
      router.addRoute(dynamicRoute)
    }
  },
  actions: {
    FETCH_MENU_LIST({commit}){
      return api.getMenuListApi().then((res) => {
        console.log(res);
        let userMenu = recursionRoutes(res.data.menuList, routes.children);
        console.log("11userMenu", userMenu);
        commit('SET_USER_METU',userMenu)
      });

    }
  },
  modules: {},
};